package com.qyhl.module_activities.act.user;

import android.widget.ImageButton;
import android.widget.RelativeLayout;

import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.flyco.tablayout.SlidingTabLayout;
import com.gyf.immersionbar.ImmersionBar;
import com.qyhl.module_activities.R;
import com.qyhl.module_activities.R2;
import com.qyhl.module_activities.act.ActivityTempFragment;
import com.qyhl.module_activities.act.ActivityTempPresenter;
import com.qyhl.webtv.basiclib.base.BaseActivity;
import com.qyhl.webtv.basiclib.base.BaseIViewPresenter;
import com.qyhl.webtv.basiclib.utils.ContextUtilts;
import com.qyhl.webtv.basiclib.utils.StringUtils;
import com.qyhl.webtv.commonlib.constant.ARouterPathConstant;
import com.qyhl.webtv.commonlib.utils.config.HomeThemeColorUtil;
import com.umeng.analytics.MobclickAgent;

import java.lang.reflect.Field;
import java.util.ArrayList;

import butterknife.BindView;

/**
 * Created by qyhl on 2017/12/15.
 *
 * @author qyhl
 * 我的活动
 */
@Route(path = ARouterPathConstant.ACTIVITY_MINE, extras = ARouterPathConstant.LOGIN_NEEDED)
public class MyActivityActivity extends BaseActivity {
    @BindView(R2.id.acttablayout)
    SlidingTabLayout act_tablayout;
    @BindView(R2.id.act_vp)
    ViewPager act_vp;
    @BindView(R2.id.back_btn)
    ImageButton back_btn;
    @BindView(R2.id.title_layout)
    RelativeLayout titleLayout;

    private ArrayList<Fragment> fragmentList;


    @Override
    protected int getContentView() {
        return R.layout.act_activity_my_activity;
    }

    @Override
    protected void setImmersionBar(ImmersionBar mImmersionBar) {
        setDefaultImmerBar();
    }

    @Override
    protected BaseIViewPresenter initBaseIViewPresenter() {
        return null;
    }

    @Override
    protected void init() {
        back_btn.setOnClickListener(v -> finish());

        try {
            Class<? extends SlidingTabLayout> aClass = act_tablayout.getClass();
            Field f = aClass.getDeclaredField("mTabPadding");
            f.setAccessible(true);
            f.set(act_tablayout, StringUtils.dip2px(this, 15));
        } catch (Exception e) {
            e.printStackTrace();
        }
        fragmentList = new ArrayList<>();
        fragmentList.add(ActivityTempFragment.newInstance("", false, ActivityTempPresenter.DATA_TYPE_JOINED));
        fragmentList.add(ActivityTempFragment.newInstance("", false, ActivityTempPresenter.DATA_TYPE_COLLECTION));
        act_vp.setAdapter(new FragmentPagerAdapter(this.getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                return fragmentList.get(position);
            }

            @Override
            public int getCount() {
                return fragmentList.size();
            }

            @Override
            public CharSequence getPageTitle(int position) {
                if (position == 0) {
                    return "已报名活动";
                } else {
                    return "已收藏活动";
                }
            }
        });
        act_tablayout.setViewPager(act_vp);
        act_tablayout.setTextSelectColor(ContextCompat.getColor(ContextUtilts.getInstance().getmContext(), R.color.global_base_0));
        act_tablayout.setTextUnselectColor(HomeThemeColorUtil.getTabNormalColor());
        act_tablayout.getTitleView(0).getPaint().setFakeBoldText(true);
    }

    @Override
    protected void setListener() {

    }

    @Override
    public void onResume() {
        super.onResume();
        //baidu
        //umeng
        MobclickAgent.onPageStart("我的活动");
        MobclickAgent.onResume(this);
    }

    @Override
    public void onPause() {
        super.onPause();
        //baidu
        //umeng
        MobclickAgent.onPageEnd("我的活动");
        MobclickAgent.onPause(this);
    }
}
